package com.ruoyi.stock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockCurrent;
import com.ruoyi.stock.service.IStockCurrentService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 股票当前信息Controller
 *
 * @author makun
 * @date 2021-11-14
 */
@RestController
@RequestMapping("/stock/current")
public class StockCurrentController extends BaseController {
  @Autowired private IStockCurrentService stockCurrentService;

  /** 查询股票当前信息列表 */
  @PreAuthorize("@ss.hasPermi('stock:current:list')")
  @GetMapping("/list")
  public TableDataInfo list(StockCurrent stockCurrent) {
    startPage();
    List<StockCurrent> list = stockCurrentService.selectStockCurrentList(stockCurrent);
    return getDataTable(list);
  }

  /** 导出股票当前信息列表 */
  @PreAuthorize("@ss.hasPermi('stock:current:export')")
  @Log(title = "股票当前信息", businessType = BusinessType.EXPORT)
  @GetMapping("/export")
  public AjaxResult export(StockCurrent stockCurrent) {
    List<StockCurrent> list = stockCurrentService.selectStockCurrentList(stockCurrent);
    ExcelUtil<StockCurrent> util = new ExcelUtil<StockCurrent>(StockCurrent.class);
    return util.exportExcel(list, "股票当前信息数据");
  }

  /** 获取股票当前信息详细信息 */
  @PreAuthorize("@ss.hasPermi('stock:current:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(stockCurrentService.selectStockCurrentById(id));
  }

  /** 新增股票当前信息 */
  @PreAuthorize("@ss.hasPermi('stock:current:add')")
  @Log(title = "股票当前信息", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody StockCurrent stockCurrent) {
    return toAjax(stockCurrentService.insertStockCurrent(stockCurrent));
  }

  /** 修改股票当前信息 */
  @PreAuthorize("@ss.hasPermi('stock:current:edit')")
  @Log(title = "股票当前信息", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody StockCurrent stockCurrent) {
    return toAjax(stockCurrentService.updateStockCurrent(stockCurrent));
  }

  /** 删除股票当前信息 */
  @PreAuthorize("@ss.hasPermi('stock:current:remove')")
  @Log(title = "股票当前信息", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(stockCurrentService.deleteStockCurrentByIds(ids));
  }
}
